package com.kkd.kkdapp.adapter;

import java.util.List;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.view.RoundView;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyTotalAssetsAdapter extends BaseAdapter {

	private Context context;
	private List<String> tvArr;
	private List<String> colorArr;
	private List<String> valueArr;

	public MyTotalAssetsAdapter(Context context, List<String> tvArr,
			List<String> colorArr, List<String> valueArr) {

		this.context = context;
		this.tvArr = tvArr;
		this.colorArr = colorArr;
		this.valueArr = valueArr;

	}

	@Override
	public int getCount() {
		return tvArr.size();
	}

	@Override
	public Object getItem(int position) {
		return tvArr.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder mViewHolder;
		if (convertView == null) {
			mViewHolder = new ViewHolder();
			convertView = View.inflate(context,
					R.layout.mytotalassets_listview_item, null);
			mViewHolder.regular_estimate1 = (TextView) convertView
					.findViewById(R.id.regular_estimate1);
			mViewHolder.regular_estimate2 = (TextView) convertView
					.findViewById(R.id.regular_estimate2);
			mViewHolder.pre_income_tv = (TextView) convertView
					.findViewById(R.id.pre_income_tv);
			mViewHolder.roundView_estimate = (RoundView) convertView
					.findViewById(R.id.roundView_estimate);
			mViewHolder.pre_income_tv1 = (TextView) convertView
					.findViewById(R.id.pre_income_tv1);
			convertView.setTag(mViewHolder);
		} else {
			mViewHolder = (ViewHolder) convertView.getTag();
		}
		mViewHolder.regular_estimate2.setVisibility(View.VISIBLE);
		if (tvArr.get(position).indexOf(",") == -1) {
			mViewHolder.regular_estimate1.setText(tvArr.get(position));
			mViewHolder.regular_estimate2.setVisibility(View.GONE);
		} else {
			String[] tv = tvArr.get(position).split(",");
			mViewHolder.regular_estimate1.setText(tv[0]);
			mViewHolder.regular_estimate2.setText(tv[1]);
		}
		mViewHolder.roundView_estimate.setColor(Color.parseColor(colorArr
				.get(position)));
		mViewHolder.pre_income_tv1.setVisibility(View.VISIBLE);
		if (valueArr.get(position).indexOf("&") == -1) {
			mViewHolder.pre_income_tv.setText(valueArr.get(position) + "元");
			mViewHolder.pre_income_tv1.setVisibility(View.GONE);
		} else {
			String[] strTv = valueArr.get(position).split("&");
			mViewHolder.pre_income_tv.setText(strTv[0] + "元");
			mViewHolder.pre_income_tv1.setText(strTv[1] + "元");
		}
		return convertView;
	}

	class ViewHolder {
		TextView regular_estimate1, regular_estimate2, pre_income_tv,
				pre_income_tv1;
		RoundView roundView_estimate;
	}

}
